import java.util.ArrayList;
import java.util.List;

/**
 * 1941. 检查是否所有字符出现次数相同
 * https://leetcode-cn.com/problems/check-if-all-characters-have-equal-number-of-occurrences/
 */
public class Solutions_1941 {
    public static void main(String[] args) {
        String s1 = "abacbc";  // output: true
        String s2 = "aaabb";  // output: false

        List<String> inputs = new ArrayList<>();
        inputs.add(s1);
        inputs.add(s2);

        for (String input : inputs) {
            boolean result = areOccurrencesEqual(input);
            System.out.println(result);
        }
    }

    public static boolean areOccurrencesEqual(String s) {
        int[] map = new int[26];
        char[] arr = s.toCharArray();
        for (char c : arr) {
            map[c - 'a'] ++;
        }
        int cnt = -1;
        for (int i = 0; i < 26; i++) {
            if (map[i] == 0) {
                continue;
            }
            if (cnt < 0) {
                cnt = map[i];
            } else if (map[i] != cnt) {
                // 次数不一致
                return false;
            }
        }
        return true;
    }
}
